function setMyCookie(name, value, time) {
  if (time) {
    var strsec = getsec(time)
  }
  var exp = new Date()
  exp.setTime(exp.getTime() + strsec * 1)
  document.cookie = name + '=' + value + ';expires=' + exp.toGMTString()
}

// 读取baicookies
function getMyCookie(name) {
  if (document.cookie) {
    var allCookie = document.cookie.split(';')
    for (var i = 0; i < allCookie.length; i++) {
      var arr2 = allCookie[i].split('=')
      if (arr2[0] === name) {
        return arr2[1]
      }
      return ''
    }
  }
}

// 删除baicookies
function delMyCookie(name) {
  var exp = new Date()
  exp.setTime(exp.getTime() - 1)
  var cval = getMyCookie(name)
  if (cval) document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString()
}
function getsec(str) {
  // alert(str)
  var str1 = str.substring(1, str.length) * 1
  var str2 = str.substring(0, 1)
  if (str2 === 's') {
    return str1 * 1000
  } else if (str2 === 'm') {
    return str1 * 60 * 1000
  } else if (str2 === 'h') {
    return str1 * 60 * 60 * 1000
  } else if (str2 === 'd') {
    return str1 * 24 * 60 * 60 * 1000
  }
}

export { setMyCookie, getMyCookie, delMyCookie }
